package main

func main() {

}

func preorderTraversal(root *TreeNode) []int {

	vals := []int{}
	var preorder func(*TreeNode)

	preorder = func(node *TreeNode) {
		if node == nil {
			return
		}

		vals = append(vals, node.Val)
		preorder(node.Left)
		preorder(node.Right)
	}

	preorder(root)

	return vals
}

type TreeNode struct {
	Val   int
	Left  *TreeNode
	Right *TreeNode
}
